package com.learn.designPatterns.structuralType.FlyWeight;

import java.util.HashMap;
import java.util.Map;

/**
 * @classname:
 * @Description:
 * @author: yfpu
 * @Date: 2018-10-31 17:18
 */
public class FlyWeightFactory {

    private Map<String, FlyWeight> flyWeightMap = new HashMap<>();

    FlyWeight getFlyWeight(String intrinsicState) {
        FlyWeight flyWeight = flyWeightMap.get(intrinsicState);
        if (flyWeight == null) {
            flyWeight = new ConcreteFlyWeight(intrinsicState);
            flyWeightMap.put(intrinsicState, flyWeight);
        }

        return flyWeight;
    }
}
